<template lang="html">
  <div class="download">
    <div class="app_info">
      <div class="app_logo"></div>
      <div class="app_tip">
        <h2>即刻出发</h2>
        <h3>用美好装满家</h3>
      </div>
      <div class="download_btn" @click="download"> 立即下载 </div>
    </div>
    <div class="fiex_box" v-if="show_tips" @click="closeTips"></div>
  </div>
</template>

<script>
import Tool from '@/utils/tool'
export default {
  data () {
    return {
      show_tips: false
    }
  },
  methods: {
    closeTips () {
      this.show_tips = false
    },
    download () {
      let ua = Tool.isSys()
      switch (ua) {
        case 'android':
          // this.$toast('下载中...')
          this.getApk()
          break
        case 'ios':
          window.location = 'https://apps.apple.com/cn/app/id1465848351'
          break
        case 'wx':
          this.show_tips = true
          break
        default:
          this.getApk()
      }
    },
    getApk () {
      this.$toast({
        mask: true,
        duration: 0,
        message: '下载中...'
      })
      return new Promise((resolve, reject) => {
        this.$Axios({ url: 'client_update_version', params: { device_type: 'ANDROID' }, method: 'get' }).then((resp) => { // 请求成功
          if (resp.return_code === '0000') {
            if (resp.data && resp.data.backage_url) {
              this.$toast.clear()
              window.location = resp.data.backage_url
            } else {
              this.$toast.clear()
              this.$toast({ message: '下载失败' })
            }
          }
          resolve(resp)
        }).catch((error) => { // 请求失败
          this.$toast.clear()
          this.$toast({ message: '下载失败' })
          this.$_requestInterceptor('error', error)
          reject(error)
        })
      })
    }
  }
}
</script>

<style lang="css" scoped>
</style>
